package com.yanqu.backendweb.validation.constraints;

import com.yanqu.backendweb.validation.validators.CustomizerValidService;
import com.yanqu.backendweb.validation.validators.CustomizerValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @author duli
 * @version 1.0
 * @date 2020/22/01 11:44
 * @Description 使用自定义的service验证，service 需要实现 {@link CustomizerValidService} 接口，并由spring接管
 */

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Constraint(validatedBy = {CustomizerValidator.class})
@Repeatable(Customizer.List.class)
public @interface Customizer {

    String message() default "验证错误";

    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default { };

    Class<? extends CustomizerValidService> value();

    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
    @Retention(RUNTIME)
    @Documented
    public @interface List {
        Customizer[] value();
    }
}
